/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package vista;

import Consultas.Logica;
import bo.boPersona;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import mundo.Empleado;
import mundo.Persona;

/**
 *
 * @author USUARIO WINDOWS
 */
public class vistaLogeo extends javax.swing.JFrame {
    

    /**
     * Creates new form vistaLogeo
     */
    public vistaLogeo() throws SQLException {
        initComponents();
        setTitle("Moto Locura");
        setLocation(500, 200);  
        administrador = new vistaAdministrador();
        empleado = new vistaEmpleado();
        persona = new boPersona();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        tfUsuario = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        tfContrasena = new javax.swing.JPasswordField();
        bIngresar = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Logeo");
        setBackground(new java.awt.Color(255, 255, 255));
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel1.setText("Usuario");
        getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(91, 74, -1, -1));
        getContentPane().add(tfUsuario, new org.netbeans.lib.awtextra.AbsoluteConstraints(202, 71, 123, -1));

        jLabel2.setText("Contraseña");
        getContentPane().add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(91, 112, 68, -1));

        tfContrasena.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tfContrasenaActionPerformed(evt);
            }
        });
        getContentPane().add(tfContrasena, new org.netbeans.lib.awtextra.AbsoluteConstraints(202, 109, 123, -1));

        bIngresar.setBackground(new java.awt.Color(204, 204, 204));
        bIngresar.setText("Ingresar");
        bIngresar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bIngresarActionPerformed(evt);
            }
        });
        getContentPane().add(bIngresar, new org.netbeans.lib.awtextra.AbsoluteConstraints(159, 147, 100, -1));

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        jLabel3.setText("Moto Locura");
        getContentPane().add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 20, 212, 42));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void tfContrasenaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tfContrasenaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tfContrasenaActionPerformed

    private void bIngresarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bIngresarActionPerformed
        try {
            // TODO add your handling code here:
            String a=tfUsuario.getText();
            String b=tfContrasena.getText(); 
                 boolean resultado=logeo.buscarEmpleado(a, b);
            if (resultado == true)
                     {
                System.out.println(logeo.getIdAdmin());
                administrador.setIdAdmin(logeo.getIdAdmin());
                administrador.setVisible(true);
                administrador.setLocation(500, 200);
               
                this.setVisible(false);
                     }
            else {
           boolean resultadoa= logeo.buscarEmpleadoE(a, b);
         if (resultadoa== true){
             System.out.println(logeo.getIdEmple());
             empleado.setIdEmple(logeo.getIdEmple());
                empleado.setVisible(true);
                empleado.setLocation(100, 200);
               this.setVisible(false);
           
         }
                     
            }
        
        } catch (Exception e) {
            Logger.getLogger(vistaLogeo.class.getName()).log(Level.SEVERE, null, e);
        }
    }//GEN-LAST:event_bIngresarActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(vistaLogeo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(vistaLogeo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(vistaLogeo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(vistaLogeo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    new vistaLogeo().setVisible(true);
                } catch (SQLException ex) {
                    Logger.getLogger(vistaLogeo.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bIngresar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPasswordField tfContrasena;
    private javax.swing.JTextField tfUsuario;
    // End of variables declaration//GEN-END:variables
    private vistaAdministrador administrador;
    private boPersona persona;
    private Logica logeo = new Logica();
    private vistaEmpleado empleado;
    
    
}
